package com.xiao.bargain.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.Query;

import com.xiao.bargain.dao.BarginDao;
import com.xiao.bargain.entity.BarginEntity;
import com.xiao.bargain.service.BarginService;


@Service("barginService")
public class BarginServiceImpl extends ServiceImpl<BarginDao, BarginEntity> implements BarginService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BarginEntity> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("huodong_status");
        IPage<BarginEntity> page = this.page(
                new Query<BarginEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }
    @Override
    public void tosave(BarginEntity bargin) {
        bargin.setXiangouNumber(1);
        if(bargin.getBarginRenshu()!=null){
            bargin.setKanroots(1);
           bargin.setKanyu( bargin.getGoodsPrice()-bargin.getGoodsDijia());
        }else if(bargin.getBarginMoney()!=null){
            bargin.setKanyu( bargin.getGoodsPrice()-bargin.getGoodsDijia());
            bargin.setKanroots(2);
        }
        bargin.setHuodongStatus("0");
        bargin.setBuystatus(0);
        baseMapper.insert(bargin);
    }
}